
const sendPost = (url, jsonData, isJson) => {
    // /csjiana/api/savePaymentOrder
    //let url = "http://192.168.1.18:8979/csjiana/api/savePaymentBills";
    console.log(Constant.UI_SDK_VERSION + "保存地址：", url);
    sleep(2000);

    // http.__okhttp__.setTimeout(30*1000);
    const isJsonFormat = isJson || "YES";
    if (isJsonFormat === "YES") {
        jsonData.country = "jiana";
    }

    http.postJson(url, jsonData, {}, (res) => {
        console.log(Constant.UI_SDK_VERSION + "请求返回======");
        try {
            let bodyStr = res.body.string();
            let result = JSON.parse(bodyStr);
            console.log(result);
        } catch (e) {
            console.log(e)
            return null;
        }
    });
}

const sendPostSync = (url, jsonData, isJson) => {
    // /csjiana/api/savePaymentOrder
    console.log(Constant.UI_SDK_VERSION + "保存地址：", url);
    sleep(2000);

    try {
        // http.__okhttp__.setTimeout(30*1000);
        const isJsonFormat = isJson || "YES";
        if (isJsonFormat === "YES") {
            jsonData.country = "jiana";
        }
        // console.log("body", jsonData);

        let res = http.postJson(url, jsonData);
        let bodyStr = res.body.string();
        let result = JSON.parse(bodyStr);
        console.log(result);
        let code = result.code + "";
        let msg = result.msg || "";

        if (code.length > 0 && (code === "0")) {
            return result.data;
        } else {
            toast(msg);
            return null;
        }
    } catch (e) {
        console.log(e)
        return null;
    }
}


module.exports = {
    sendPost: sendPost,
    sendPostSync: sendPostSync
};